package com.cjm.algorithm.queue;

import java.util.Arrays;
import java.util.List;
import java.util.Stack;

public class Ti240421150 {
    private List<String> queue = Arrays.asList("+", "-", "*", "/");
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<Integer>();
        for (int i = 0; i < tokens.length; i++) {
            String token = tokens[i];
            if (!queue.contains(token)) {
                stack.push(Integer.valueOf(token));
                continue;
            }
            Integer one = stack.pop();
            Integer two = stack.pop();
            if ("+".equals(token)) {
                stack.push(two + one);
            }
            if ("-".equals(token)) {
                stack.push(two - one);
            }
            if ("*".equals(token)) {
                stack.push(two * one);
            }
            if ("/".equals(token)) {
                stack.push(two / one);
            }
        }
        return stack.pop();
    }
}
